package com.paomi.client.activity.detail.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.detail.model.PraiseSeatBean;

import java.util.List;

/**
 * Created by pc on 2018/3/19.
 * 座位适配的列表
 */

public class SeatListAdapter extends RecyclerView.Adapter<SeatListAdapter.ViewHolder>{
    Context context;
    List<PraiseSeatBean.PraiseSeatJson> mlist;
    SeatListAdapter.OnItemClick onClickListener;

    public void OnItemClick(SeatListAdapter.OnItemClick onClickListener) {
        this.onClickListener = onClickListener;
    }


    public SeatListAdapter(Context context, List<PraiseSeatBean.PraiseSeatJson> list) {
        this.context = context;
        this.mlist = list;
    }

    @Override
    public SeatListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SeatListAdapter.ViewHolder(LayoutInflater.from(context).inflate(R.layout.ticket_price_item_layout, parent, false));
    }

    @Override
    public void onBindViewHolder(final SeatListAdapter.ViewHolder holder, final int position) {
        PraiseSeatBean.PraiseSeatJson ticket=mlist.get(position);
        holder.price_tv.setText( ticket.getName());
        if(ticket.getType()==0){
            holder.relative_view.setBackgroundResource(R.drawable.bg_ticket_un);
            holder.price_tv.setTextColor(context.getResources().getColor(R.color.text_66));
        }else if(ticket.getType()==1){
            holder.relative_view.setBackgroundResource(R.drawable.bg_ticket_on);
            holder.price_tv.setTextColor(context.getResources().getColor(R.color.main_color));
        }
//        if (ticket.getName()!=null&&ticket.children.size()>0&&ticket.status) {
//            if (ticket.children.get(0).getPrice()!=null){
//                double face_price = Double.valueOf(ticket.getName());
//                double pricec = Double.valueOf(ticket.children.get(0).getPrice());
//                Log.e("price", face_price + "," + pricec);
//                if (face_price > pricec) {
//                    Log.e("1", "---------------");
//                    holder.iv_price_info.setVisibility(View.VISIBLE);
//                    holder.iv_price_info.setImageResource(R.mipmap.icon_price_fall);
//                } else if (face_price < pricec) {
//                    Log.e("2", "---------------");
//                    holder.iv_price_info.setVisibility(View.VISIBLE);
//                    holder.iv_price_info.setImageResource(R.mipmap.icon_price_rise);
//                } else {
//                    Log.e("3", "---------------");
//                    holder.iv_price_info.setVisibility(View.GONE);
//                }
//            }
//
//        }
        holder.relative_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onClickListener!=null){
                    for (int i=0;i<mlist.size();i++){
                        if (i==position){
                            mlist.get(i).setType(1);
                        }else{
                            mlist.get(i).setType(0);
                        }
                    }
                    notifyDataSetChanged();
                    onClickListener.setOnItemClick(holder.relative_view,position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView price_tv;//票价显示
        TextView add_tv;//
        LinearLayout relative_view;//点击的布局显示
        ImageView iv_price_info;//票价显示"折"和“溢”

        public ViewHolder(View itemView) {
            super(itemView);
            relative_view = (LinearLayout) itemView.findViewById(R.id.relative_view);
            iv_price_info = (ImageView) itemView.findViewById(R.id.iv_price_info);
            price_tv = (TextView) itemView.findViewById(R.id.price_tv);
            add_tv = (TextView) itemView.findViewById(R.id.add_tv);
        }
    }

    public interface OnItemClick {
        void setOnItemClick(View view, int pos);
    }
}
